package com.cnc.tag;

import javax.servlet.jsp.JspException;

import org.apache.struts.util.RequestUtils;
import org.apache.struts.util.ResponseUtils;

import com.cnc.ssm.ISsmService;

/**
 * 从字典表中获得某类别的所有值 <br>
 * Example: <custom:fetchFromDict dictTypeCode="110" dictValue="${corpNature}"></custom:fetchFromDict>
 */
public class FetchNameByCodeTag extends LtcmTag {
	private String name;

	private String property;

	private String codeValue;

	private String codeType;


	public int doEndTag() throws JspException {
		ISsmService ssmService = (ISsmService) this.getBean(com.cnc.bas.util.Constants.BEAN_NAME_SSM);
		if (codeValue == null || codeValue.length() < 1) {
			Object oValue = RequestUtils.lookup(pageContext, name, property, null);
			if (oValue != null)
				codeValue = oValue.toString();
		}

		String result = "";
		if (codeValue != null && codeValue.trim().length() > 0) {
			result = ssmService.getNameByCode(codeType, codeValue);
		}
		ResponseUtils.write(pageContext, result);
		this.codeValue = "";
		return (EVAL_PAGE);
	}


	public String getCodeType() {
		return codeType;
	}


	public void setCodeType(String codeType) {
		this.codeType = codeType;
	}


	public String getCodeValue() {
		return codeValue;
	}


	public void setCodeValue(String codeValue) {
		this.codeValue = codeValue;
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

}
